import time

from selenium.webdriver.common.by import By

from common.Utils import ForumDriver


class ForumDetail:
    url=""
    driver=""
    def __init__(self):
        self.url="http://127.0.0.1:58080/index.html"
        self.driver=ForumDriver.driver
        self.driver.get(self.url)
    # 返回首页
    def Back(self):
        self.driver.find_element(By.CSS_SELECTOR, "#nav_board_index > a").click()
    #我的帖子
    def MyPost(self):
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_profile").click()
        actual=self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-header.d-print-none > div > div > div.col > div > div:nth-child(1)").text
        print(actual)
    #删除帖子
    # def DeletePost(self):
    #     self.driver.find_element(By.CSS_SELECTOR, "#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong").click()
    #     self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-body > div > div > div:nth-child(1) > div.col-9.card.card-lg > div.card-footer.bg-transparent.mt-auto.justify-content-end > div > div:nth-child(3) > div > a > span").click()
    #     time.sleep(1)
    #     self.driver.find_element(By.CSS_SELECTOR, "#details_artile_delete").click()


    #个人中心
    def PersonalCenter(self):
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_settings").click()
        actual=self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-body > div > div > div > div.col-3.d-none.d-md-block.border-end > div > div > a").text
        print(actual)
        assert actual == "我的账户"
    # #修改头像
    # def ModifyPicture(self):
    #     self.driver.find_element(By.CSS_SELECTOR, "#bit-forum-content > div.page-body > div > div > div > div.col.d-flex.flex-column > div > div.row.align-items-center > div:nth-child(2) > a").send_keys("C:\Users\20627\Pictures\Screenshots")

    #修改邮箱
    def ModifyMailbox(self):
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_email").send_keys("123124@qq.com")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_email").click()

    #修改电话号码
    def ModifyPhone(self):
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_phoneNum").send_keys("123456789")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_phoneNum").click()
    #修改昵称
    def ModifyNickname(self):
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#setting_input_nickname").send_keys("C++大王")
        self.driver.find_element(By.CSS_SELECTOR, "#setting_submit_nickname").click()

    #修改密码
    def ModifyPassword(self):
        # 向下滚动到页面底部
        self.driver.execute_script("window.scrollBy(0, document.body.scrollHeight)")
        time.sleep(2)
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").clear()
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_oldPassword").send_keys("123456")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_newPassword").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_input_passwordRepeat").send_keys("123")
        self.driver.find_element(By.CSS_SELECTOR, "#settings_submit_password").click()

    #退出
    def Quit(self):
        self.driver.find_element(By.CSS_SELECTOR, "#index_nav_avatar").click()
        self.driver.find_element(By.CSS_SELECTOR, "#index_user_logout").click()
        self.driver.find_element(By.CSS_SELECTOR, "body > div > div > div > div:nth-child(1) > div > div.card.card-md > div > h2")
